<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE HTML>
<html>
  <head>
     <title>
		设置秒杀
	</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css"  />
</head>
<script src="${pageContext.request.contextPath}/js/jquery-1.6.3.js"></script>
 <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#search").click(function(){
		if($("#searchcontent").val()==null||$("#searchcontent").val()==""){
			alert("请填写搜索关键字");
			return false;
		}
});
$("#pagea").click(function(){
		var page=$("#page").html();
		var pageNum=$("#pageNum").html();
		if(page==1){
		return false;
		}
		
});
$("#pagea2").click(function(){
		var page=$("#page").html();
		var pageNum=$("#pageNum").html();
		if(page==pageNum){
			return false;
		}
		
});
});
</script>
<body style="width: 100%;height: 100%">
    	<div style="margin-left: 70%">
    		<form action="${pageContext.request.contextPath}/commodity/searchComm.action?bs=5" method="post">
    		<input id="searchcontent" type="text" style="border:1px solid #FF7F00" placeholder="商品标题或品牌" name="search">
    		<input type="hidden" value="3" name="bs">
    		<input id="search" type="submit" value="搜索" style="background: #FF7F00;color:#fff;height: 30px;">
    		</form>
    	</div>
    	<c:if test="${commodity!=null }">
    	<c:forEach items="${commodity }" var="comm">
    	<div class="commodity" id="commodity${comm.id }" >
    		<img src="${pageContext.request.contextPath}/file/img/${comm.titleimg }" >
    		<div style="width:400px;height:100px;margin-left: 10px;margin-top:10px;float: left">
    			<span style="font-size: 16px;font-weight: 600">商品名称:${comm.title }</span>
    			<br><span style="font-size: 16px;font-weight: 600">商品价格:${comm.price }</span>
    			<br><span style="font-size: 16px;font-weight: 600">创建时间:
    			<fmt:formatDate value="${comm.cdate }" pattern="yyyy-MM-dd HH:mm:ss"/></span>
    			<br><span style="font-size: 16px;font-weight: 600">商品类型:${comm.categoryid }</span>
    		</div>
    		<div style="width:300px;height:100px;margin-left: 10px;margin-top:10px;float: left">
    			<span style="font-size: 16px;font-weight: 600">商品品牌:${comm.brand }</span>
    			<br><span style="font-size: 16px;font-weight: 600">商品库存:${comm.stock }</span>
    			<br><span style="font-size: 16px;font-weight: 600">是否上架:
    			<c:if test="${comm.shelves==0 }">已上架</c:if>
    			<c:if test="${comm.shelves==1 }">未上架</c:if>
    			<br>
    			<span>商品ID:</span>
    			<span>${comm.id}</span>
    			</span>
    		</div>
    		<div class="shelvesbtn" id="shelvesbtn${comm.id}" onclick="return setkill(${comm.id},this)">
    		<span style="font-size: 20px;color:#fff;">设<br>置<br>秒<br>杀</span>
    		</div>
    	</div>
    	<div class="seckilldiv" id="seckilldiv${comm.id }" style="display: none">
    		<label>秒杀价格</label>
    		<input type="text" id="commprice${comm.id }" > 
    		<label style="margin-left:10px">商品数量</label>
    		<input type="text" id="commnum${comm.id }" style="width:100px;"> 
    		<br>
    		<label>开始时间:</label>
    		<select id="yyyy${comm.id }" class="yyyy" >
							
			</select>
			<select id="mm${comm.id }" class="mm">
							
			</select>
			<select id="dd${comm.id }" class="dd">
							
			</select>
			<select id="HH${comm.id }" class="HH">
							
			</select>
			<select id="MM${comm.id }" class="MM">
							
			</select>
			<br>
    		<label>结束时间:</label>
    		<select id="eyyyy${comm.id }" class="eyyyy" >
							
			</select>
			<select id="emm${comm.id }" class="emm">
							
			</select>
			<select id="edd${comm.id }" class="edd">
							
			</select>
			<select id="eHH${comm.id }" class="eHH">
							
			</select>
			<select id="eMM${comm.id }" class="eMM">
							
			</select>
    		<button class="submitkill" onclick="return submit(${comm.id });">提&nbsp;&nbsp;&nbsp;交</button>
    	</div>
    	</c:forEach>
    	</c:if>
    	<c:if test="${commodity==null }">
    		<h3 style="margin-left: 43%">没有找到商品</h3>
    	</c:if>
    	<c:if test="${commodity!=null }">
    			   <!-- 翻页 -->
	      <div style="margin-left: 72%;margin-top: 3%" >
	      		<a id="pagea" style="color:#FF7F00" href="${pageContext.request.contextPath}/commodity/listAll.action?page=${page-1}&kill=kill">上一页</a>
	      		共<span id="pageNum">${pageNum }</span>页,
	      		当前第<span style="color:#FF7F00" id="page">${page+1}</span>页
	      		<a id="pagea2" style="color:#FF7F00" href="${pageContext.request.contextPath}/commodity/listAll.action?page=${page+1}&kill=kill">下一页</a>
	      </div>
    	</c:if>
    	<input type="hidden" value="${pageContext.request.contextPath}/" id="path">
 </body>
 <script type="text/javascript">
$(document).ready(function(e){
			var y=$(".yyyy");
			var m=$(".mm");
			var d=$(".dd");
			var h=$(".HH");
			var M=$(".MM");
			var ey=$(".eyyyy");
			var em=$(".emm");
			var ed=$(".edd");
			var eh=$(".eHH");
			var eM=$(".eMM");
			var date=new Date().Format("yyyy-MM-dd-HH-mm");  
			var arr=date.split("-");
			foreach(2017,2025,y,function(t,i){
				if(arr[0]==i){
				t.append("<option selected='selected' value='"+i+"'>"+i+"年</option>");
				ey.append("<option selected='selected' value='"+i+"'>"+i+"年</option>");
				}else{
				t.append("<option  value='"+i+"'>"+i+"年</option>");
				ey.append("<option  value='"+i+"'>"+i+"年</option>");
				}
			});
			foreach(1,31,d,function(t,i){
				if(arr[2]==i){
				t.append("<option selected='selected' value='"+i+"'>"+i+"日</option>");
				ed.append("<option selected='selected' value='"+i+"'>"+i+"日</option>");
				}else{
				t.append("<option  value='"+i+"'>"+i+"日</option>");
				ed.append("<option value='"+i+"'>"+i+"日</option>");
				}
			});
			foreach(1,12,m,function(t,i){
				if(arr[1]==i){
				t.append("<option selected='selected' value='"+i+"'>"+i+"月</option>");
				em.append("<option selected='selected' value='"+i+"'>"+i+"月</option>");
				}else{
				t.append("<option  value='"+i+"'>"+i+"月</option>");
				em.append("<option  value='"+i+"'>"+i+"月</option>");
				}
			});
			foreach(0,23,h,function(t,i){
				if(arr[3]==i){
				t.append("<option selected='selected' value='"+i+"'>"+i+"时</option>");
				eh.append("<option selected='selected' value='"+i+"'>"+i+"时</option>");
				}else{
				t.append("<option  value='"+i+"'>"+i+"时</option>");
				eh.append("<option  value='"+i+"'>"+i+"时</option>");
				}
			});
			foreach(0,59,M,function(t,i){
				if(arr[4]==i){
				t.append("<option selected='selected' value='"+i+"'>"+i+"分</option>");
				eM.append("<option selected='selected' value='"+i+"'>"+i+"分</option>");
				}else{
				t.append("<option  value='"+i+"'>"+i+"分</option>");
				eM.append("<option  value='"+i+"'>"+i+"分</option>");
				}
			});
			/*监听月份和年份改变的事件,针对2月进行天数的修改 */
			m.change(function(){
				var mm=m.val();
				if(mm>7&&(mm%2)!=0){
				foreach(1,30,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>");
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>");
				}
			});
				return false;
				}else if(mm<7&&(mm%2)==0&&mm!=2)
				{foreach(1,30,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
				return false;
				}else{
					foreach(1,31,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
				}
				var yyyy=y.val();
				var byf=String(yyyy/4).indexOf('.');
				if(mm==2){
					if((yyyy%100)==0&&(yyyy%400)==0){
						foreach(1,29,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
					return false;
					}else if(byf<0){
							foreach(1,29,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
				}else{
						foreach(1,28,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
				}
				}
			});
		y.change(function(){
				var yyyy=y.val();
				var mm=m.val();
				var byf=String(yyyy/4).indexOf('.');
				if(mm==2){
					if((yyyy%100)==0&&(yyyy%400)==0){
						foreach(1,29,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
					return false;
					}else if(byf<0){
							foreach(1,29,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
				}else{
						foreach(1,28,d,function(t,i){
				if(i==1){
				t.html("<option value='"+i+"'>"+i+"日</option>")
				}else{
				t.append("<option value='"+i+"'>"+i+"日</option>")
				}
				});
				}
				}
		});
	});
		/*封装for  */
		function foreach(l,e,d,callback){
				for(l;l<=e;l++){
					callback(d,l);
				}
		}
Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, 
        "d+": this.getDate(), 
        "H+": this.getHours(),  
        "m+": this.getMinutes(),  
        "s+": this.getSeconds(), 
        "q+": Math.floor((this.getMonth() + 3) / 3), 
        "S": this.getMilliseconds()  
    };
    var year = this.getFullYear();
    var yearstr = year + '';
    yearstr = yearstr.length >= 4 ? yearstr : '0000'.substr(0, 4 - yearstr.length) + yearstr;
    
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (yearstr + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
function submit(id){
			var y=$("#yyyy"+id).val();
			var m=Number($("#mm"+id).val());
			var d=Number($("#dd"+id).val());
			var h=Number($("#HH"+id).val());
			var M=Number($("#MM"+id).val());
			var ey=Number($("#eyyyy"+id).val());
			var em=Number($("#emm"+id).val());
			var ed=Number($("#edd"+id).val());
			var eh=Number($("#eHH"+id).val());
			var eM=Number($("#eMM"+id).val());
			var commprice=Number($("#commprice"+id).val());
			var commnum=Number($("#commnum"+id).val());
			var t=/[0-9]{1,20}/
			if(eM<=M&&eh<=h&&ed<=d&&em<=m){
				alert("结束时间不能小于开始时间!");
				return false;
			}else if(eh<h&&ed<=d&&em<=m){
				alert("结束时间不能小于开始时间!");
					return false;
			}else if(ed<d&&em<=m){
				alert("结束时间不能小于开始时间!");
				return false;
			}else if(em<m){
				alert("结束时间不能小于开始时间!");
				return false;
			}
			if(!t.test(commprice)||!t.test(commnum)||commprice==''||commnum==''){
				alert("请填写正确值!");
				return false;
			}
			if(h<10){
			h="0"+h;
			}
			if(M<10){
			M="0"+M;
			}if(eh<10){
			h="0"+h;
			}
			if(eM<10){
			M="0"+M;
			}
			var sdate=y+"-"+m+"-"+d+" "+h+":"+M;
			var edate=ey+"-"+em+"-"+ed+" "+eh+":"+eM;
			var path=$("#path").val();
			$.post(path+"SeckillController/create.action",
			{"sdate":sdate,"edate":edate,"price":commprice,"num":commnum,"id":id},
			function(datas){
					if(datas==0){
					alert("创建秒杀失败!");
					location.reload();
					}else{
					alert("创建成功!");
					$("#shelvesbtn"+id).click();
					}
			});
		
}
function setkill(id,data){
			var div=$("#seckilldiv"+id);
			if(div.css("display")=="none"){
			div.css("display","block");
			$(data).children().html("收<br>起<br>设<br>置");
			}else{
			div.css("display","none");
			$(data).children().html("设<br>置<br>秒<br>杀");
			}
}
 </script>
   <style>
   .submitkill{
   height:70px;width:100px;display:block;position: absolute;left:600px;top:13px;
   border-radius:6px;border:2px solid #EE7942;background:#EE9572;color:#fff;
   font-size:22px;
   }
   .seckilldiv{
  		 height: 95px;
		width:950px;
		border:1px solid #FF7F00;
		margin:0px auto;
		border-top: none;
		position: relative;
		padding:5px 0 0 200px;
		
   }
   .seckilldiv input{
 border:1px solid #9C9C9C;border-radius:4px;
 }
 .seckilldiv select{
  border:1px solid #9C9C9C;border-radius:4px;
 }
   .updateform{
   margin: 2px 0 0 10px;
   }
   .updateform button{
   border:2px solid;border-radius:4px;margin-left:15px;
   }
.updateclassdiv{
width:950px;min-height: 120px;background: #fff;
margin:0 auto;border:1px solid #FF7F00;border-top:none;display: none;

}
   .hiddenfile{
    position: absolute;
    overflow: hidden;
    left:34px;
    top: 7px;
    height:98px;width:98px;
    opacity: 0;
   }
   #isShelves:hover{
   background: #00EEEE;cursor: pointer;height:100%;
   }
   #noShelves:hover{
   background: #00EEEE;cursor: pointer;height:100%;
   }
  .commodity{
		height: 125px;
		width:950px;
		border:1px solid #FF7F00;
		margin:0px auto;
		margin-top: 10px;
  }
  .commodity img{
  height:98px;width:98px;margin-top: 10px;margin-left: 5px;
  border: 1px solid #FF7F00;float:left;
  }
  .hiddenfile:HOVER{
  		cursor: pointer;
  }
    .commodityhidden{
		height: 125px;
		width:950px;
		border:1px solid #FF7F00;
		margin:0px auto;
		display: none;
		margin-top: 10px;
  }
  .commodityhidden img{
  height:98px;width:98px;margin-top: 10px;margin-left: 5px;
  border: 1px solid #FF7F00;float:left;
  }
 .shelvesbtn{
  width:70px;height:124px;float: left;
  background:red;text-align: center;margin-left:55px;
  padding-top: 10px;
  }
    .shelvesbtn:HOVER{
  background: #EE6A50;cursor: pointer;
  }
   .shelvesbtnhidden{
  width:70px;height:125px;float: left;
  background: #FF7F00;text-align: center;margin-left:55px;
 
  }
    .shelvesbtnhidden span{
    display: block;width:100%;height: 50%;padding-top:13px;
    }
    .shelvesbtnhidden span:HOVER{
  background: #FF0000;cursor: pointer;
  }
   </style>
</html>